import request from '@/axios'
import type { ApplicationOption, ApplicationTableView, ApplicationForm } from './types'

const pathPrefix = '/api/application'

export const query = (data: PaginationRequest): Promise<PaginationResponse<ApplicationTableView>> => {
    return request.post({
        url: `${pathPrefix}/query`,
        data
    })
}

export const get = (id: string): Promise<ApplicationForm> => {
    return request.get({
        url: `${pathPrefix}/${id}`
    })
}

export const add = (data: ApplicationForm): Promise<ApiResult> => {
    return request.post({
        url: `${pathPrefix}`,
        data
    })
}

export const edit = (id: string, data: ApplicationForm): Promise<ApiResult> => {
    return request.put({
        url: `${pathPrefix}/${id}`,
        data
    })
}

export const remove = (id: string): Promise<ApiResult> => {
    return request.delete({
        url: `${pathPrefix}/${id}`
    })
}


export const getGroupOptions = (): Promise<OptionGroup[]> => {
    return request.get({
        url: `${pathPrefix}/option-group`
    })
}

export const tenantOptions = (): Promise<OptionItem[]> => {
    return request.get({
        url: `${pathPrefix}/tenant/options`
    })
}